// pages/style/style.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    styleObject: {
      'font-size': '20px',
      color: 'red'
    },
    styleStr: '',
    color:'blue',
    classList:['color','font'],
    isShow:1,
    books:[
      {name:'JavaScript',price:'20'},
      {name:'Java',price:'40'},
      {name:'Python',price:'15'}
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 获取系统信息
    let info = wx.getSystemInfoSync();
    console.log(info);
    let width = info.windowWidth,
      height = info.windowHeight;
    let rpxHeight = 750 / width * height;
    console.log(rpxHeight);

    // 规定屏幕宽为750rpx。
    // 1px = 750 / windowWidth (rpx)
    // 1rpx = windowWidth / 750 (px)

    // 小程序中style属性不能直接访问对象，需要把对象转换为字符串
    let so = this.data.styleObject;
    let str = '';
    for (let key in so) {
      str += `${key}:${so[key]};`
    }
    this.setData({
      styleStr: str
    })
  },
  changeShow(){
    let isShow = this.data.isShow;
    switch(isShow){
      case 1:
      isShow = 2;
      break;
      case 2: isShow = 3; break;
      case 3: isShow = 1; break;
    }
    this.setData({
      isShow:isShow
    })
  }
})